package com.dreamlin.gankio.base.ui

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.widget.TextView
import com.dreamlin.gankio.R
import com.dreamlin.gankio.common.dp2px


class LoadingDialog(context: Context) : Dialog(context) {

    private lateinit var tvMsg: TextView

    init {
        setCanceledOnTouchOutside(false)
        setContentView(R.layout.dialog_loading)
//        val view = LayoutInflater.from(context).inflate(R.layout.dialog_loading, null, false)
        tvMsg = findViewById(R.id.tv_msg)
//        setContentView(view)
        val window = window
        val lp = window!!.attributes
        lp.width = 150f.dp2px().toInt()
        lp.height = 110f.dp2px().toInt()
        lp.gravity = Gravity.CENTER
        window.attributes = lp
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

    }

    fun setLoadingMsg(msg: String?) {
        tvMsg.text = msg ?: "数据加载中..."
    }
}

